/**
 * 
 */
package cz.cuni.mff.abacs.burglar.logics.objects.agents;

import java.util.List;

import cz.cuni.mff.abacs.burglar.logics.DataMap;
import cz.cuni.mff.abacs.burglar.logics.objects.BaseInterface;
import cz.cuni.mff.abacs.burglar.logics.objects.BaseObject;
import cz.cuni.mff.abacs.burglar.logics.objects.positions.Door;
import cz.cuni.mff.abacs.burglar.logics.objects.positions.Position;


/**
 * 
 * 
 * @author abacs
 *
 */
public class Guard extends BaseAgent implements Agent {
	
	
	
	
	// -------------------------------------------------------------------------
	// constructors:
	
	
	/**
	 * 
	 * 
	 * @param id
	 * @param position
	 * @param roomIdsToVisit
	 * @param referenceMap
	 */
	public Guard(
			int id,
			Position position,
			List<Integer> roomIdsToVisit,
			DataMap referenceMap
	) {
		super(id, BaseObject.Type.GUARD, position, new GuardGoal(roomIdsToVisit), referenceMap);
		
		((GuardGoal)(this._goals)).setRoomVisited(this.getRoomId());
	}
	
	
	/**
	 * 
	 * @param original
	 * @param referenceMap
	 */
	protected Guard(Guard original, DataMap referenceMap) {
		super(original, referenceMap);
		
		((GuardGoal)(this._goals)).setRoomVisited(this.getRoomId());
	}
	
	
	// -------------------------------------------------------------------------
	
	
	/**
	 * 
	 * @return room IDs.
	 */
	public List<Integer> getRoomsToVisit() {
		return ((GuardGoal)(this._goals)).getRoomsToVisit();
	}
	
	
	/**
	 * 
	 * @return room IDs.
	 */
	public List<Integer> getAllGoalRooms() {
		return ((GuardGoal)(this._goals)).getAllGoalRooms();
	}
	
	
	// -------------------------------------------------------------------------
	
	
	@Override
	public boolean moveTo(Position stepable) {
		
		if(super.moveTo(stepable)){
			
			// also mark the new room visited
			if(stepable.isTypeOf(BaseInterface.Type.DOOR)){
				Door door = (Door)stepable;
				int[] roomIds = door.getRoomIds();
				
				((GuardGoal)(this._goals)).setRoomVisited(roomIds[0]);
				((GuardGoal)(this._goals)).setRoomVisited(roomIds[1]);
			}
			return true;
		}else{
			return false;
		}
	}
	
	
	// -------------------------------------------------------------------------
	
	
	@Override
	public void copyChangeables(Agent original) {
		
		assert(original.isTypeOf(BaseInterface.Type.GUARD));
		//Guard original_ = (Guard) original;
		
		super.copyChangeables((BaseAgent)original);
		
		((GuardGoal)(this._goals)).setRoomVisited(this.getRoomId());
	}
	
	
	@Override
	public Agent copy(DataMap reference) {
		return new Guard(this, reference);
	}
	
	
}
